package cn.wolfcode.wolf2w.util;

import cn.wolfcode.wolf2w.qurey.QueryObject;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageImpl;
import org.springframework.data.domain.Pageable;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Query;

import java.util.List;

public abstract class DBHepler {

    public static <T> Page<T>query(MongoTemplate template, Pageable pageable, Query query, Class<T> clz, QueryObject qo){

        long count = template.count(query, clz);

        if (count==0){
            return Page.empty();
        }
        query.with(pageable);
        List<T> list = template.find(query, clz);
        return new PageImpl<T>(list,pageable,count);
    }


}
